package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.TEndorsementInfoModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by HangLiu on 2017/2/20.
 */

public interface TEndorsementInfoRepository extends JpaRepository<TEndorsementInfoModel, Integer>, JpaSpecificationExecutor<TEndorsementInfoModel> {
    @Modifying
    @Query("UPDATE  TEndorsementInfoModel u SET u.state=?1  WHERE u.pdId=?2")
    void updTeampRecetInfo(String state, Integer pdId);

    @Query("select u from TEndorsementInfoModel u where u.insId=?1 and u.year=?2 and u.instype=?3 order by  u.pdId desc ")
    List<TEndorsementInfoModel> findbuyYearAndinsId(Integer insId,String year,String instype);

   @Query("select  count (u.pdId) from TEndorsementInfoModel u where u.insId=?1  and u.instype=?2 and u.state=?3 ")
    Integer findMixYear(Integer insId,String instype,String state);

    @Modifying
    @Query("UPDATE  TEndorsementInfoModel u SET u.state=?1  WHERE u.insId=?2  and u.instype=?3 and u.state=?4  and u.year>?5")
    void updateStateByMaxY(String nState,Integer insId,String instype,String oState,String year);

    @Query("select u from TEndorsementInfoModel u where u.endorsementId = ?1")
    @Modifying
    List<TEndorsementInfoModel> findByEndorsementId(String endorsementId);
}
